package com.yonyou.byb.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yonyou.byb.BybConstant;
import com.yonyou.byb.Order;
import com.yonyou.byb.RespMsg;
import com.yonyou.byb.bs.DaohuoBS;
import com.yonyou.byb.utils.JsonLogger;

@Controller
@RequestMapping(value="/v1/shop/daohuo")
public class ShopDaohuoController {
	
	@ResponseBody
	@RequestMapping(method = RequestMethod.POST)
	public RespMsg daohuo(@RequestBody Order order) {
		JsonLogger.info(order);
		
		DaohuoBS bs = new DaohuoBS();
		String orderType = order.getOrdertype();
		try {
			if (BybConstant.SALETYPE_PUHUO.equals(orderType)) {
				return bs.daohuoPuhuo(order);
			} else {
				return bs.daohuoSale(order);
			}
		} catch (Exception e) {
			RespMsg re = new RespMsg();
			re.setBillid(order.getBillid());
			re.setVstatus(RespMsg.FAILED);
			re.setErrmsg(e.getMessage());
			return re;
		}
	}

}
